﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.SqlServer.Repositories.Readers
{
	using System.Data.SqlClient;
	using Falcon.Core.Domain;

	public class UserGroupPhotoReader : IReader<UserGroupPhoto>
	{
		public void Populate(SqlDataReader reader, UserGroupPhoto entity)
		{
			entity.Id = reader.GetInt32(0);
			entity.GroupId = reader.GetInt32(1);

			entity.Photo = new UserAlbumPhoto
			{
				Id = reader.GetInt32(2),
				AlbumId = reader.GetInt32(3),
				Title = reader.GetString(4),
				Slug = reader.GetString(5),
				Created = reader.GetDateTime(6),
				User = new User
				{
					Id = reader.GetInt32(7),
					Name = reader.GetString(8),
					Slug = reader.GetString(9),
					Reputation = reader.GetInt32(10),
					Profile = new UserProfile {Title = reader.GetString(11)}
				}
			};

			if (!reader.IsDBNull(12))
			{
				entity.Photo.User.Profile.Avatar = new UserAvatar
				{
					FileName = reader.GetString(12),
					FileDiskName = reader.GetString(13),
					FilePath = reader.GetString(14),
					FileType = reader.GetString(15)
				};
			}

			entity.Photo.Attachment = new Attachment
			{
				Id = reader.GetInt32(16),
				FileName = reader.GetString(17),
				FileDiskName = reader.GetString(18),
				FilePath = reader.GetString(19),
				FileType = reader.GetString(20),
				FileExtension = reader.GetString(21),
				FileSize = reader.GetInt32(22),
				Width = reader.GetInt32(23),
				Height = reader.GetInt32(24),
				Created = reader.GetDateTime(25),
				Updated = reader.GetDateTime(26)
			};
		}
	}
}